// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.textures;

import java.util.ArrayList;
import zombie.core.opengl.SmartShader;
import zombie.popman.ObjectPool;
import zombie.util.list.PZArrayUtil;

public final class TextureCombinerCommand {
    public static final int DEFAULT_SRC_A = 1;
    public static final int DEFAULT_DST_A = 771;
    public int x = -1;
    public int y = -1;
    public int w = -1;
    public int h = -1;
    public Texture mask;
    public Texture tex;
    public int blendSrc;
    public int blendDest;
    public int blendSrcA;
    public int blendDestA;
    public SmartShader shader;
    public ArrayList<TextureCombinerShaderParam> shaderParams = null;
    public static final ObjectPool<TextureCombinerCommand> pool = new ObjectPool<>(TextureCombinerCommand::new);

    public String toString() {
        String string = System.lineSeparator();
        return "{"
            + string
            + "\tpos: "
            + this.x
            + ","
            + this.y
            + string
            + "\tsize: "
            + this.w
            + ","
            + this.h
            + string
            + "\tmask:"
            + this.mask
            + string
            + "\ttex:"
            + this.tex
            + string
            + "\tblendSrc:"
            + this.blendSrc
            + string
            + "\tblendDest:"
            + this.blendDest
            + string
            + "\tblendSrcA:"
            + this.blendSrcA
            + string
            + "\tblendDestA:"
            + this.blendDestA
            + string
            + "\tshader:"
            + this.shader
            + string
            + "\tshaderParams:"
            + PZArrayUtil.arrayToString(this.shaderParams)
            + string
            + "}";
    }

    public TextureCombinerCommand init(Texture _tex) {
        this.tex = this.requireNonNull(_tex);
        this.blendSrc = 770;
        this.blendDest = 771;
        this.blendSrcA = 1;
        this.blendDestA = 771;
        return this;
    }

    public TextureCombinerCommand initSeparate(Texture _tex, int src, int dest, int srcA, int destA) {
        this.tex = this.requireNonNull(_tex);
        this.blendSrc = src;
        this.blendDest = dest;
        this.blendSrcA = srcA;
        this.blendDestA = destA;
        return this;
    }

    public TextureCombinerCommand init(Texture _tex, int src, int dest) {
        return this.initSeparate(_tex, src, dest, 1, 771);
    }

    public TextureCombinerCommand init(Texture _tex, SmartShader _shader) {
        this.tex = this.requireNonNull(_tex);
        this.shader = _shader;
        this.blendSrc = 770;
        this.blendDest = 771;
        this.blendSrcA = 1;
        this.blendDestA = 771;
        return this;
    }

    public TextureCombinerCommand init(Texture _tex, SmartShader _shader, Texture _mask, int src, int dest) {
        this.tex = this.requireNonNull(_tex);
        this.shader = _shader;
        this.blendSrc = src;
        this.blendDest = dest;
        this.blendSrcA = 1;
        this.blendDestA = 771;
        this.mask = this.requireNonNull(_mask);
        return this;
    }

    public TextureCombinerCommand init(Texture _tex, int _x, int _y, int _w, int _h) {
        this.tex = this.requireNonNull(_tex);
        this.x = _x;
        this.y = _y;
        this.w = _w;
        this.h = _h;
        this.blendSrc = 770;
        this.blendDest = 771;
        this.blendSrcA = 1;
        this.blendDestA = 771;
        return this;
    }

    public TextureCombinerCommand initSeparate(
        Texture _tex, SmartShader _shader, ArrayList<TextureCombinerShaderParam> params, Texture _mask, int src, int dest, int srcA, int destA
    ) {
        this.tex = this.requireNonNull(_tex);
        this.shader = _shader;
        this.blendSrc = src;
        this.blendDest = dest;
        this.blendSrcA = srcA;
        this.blendDestA = destA;
        this.mask = this.requireNonNull(_mask);
        if (this.shaderParams == null) {
            this.shaderParams = new ArrayList();
        }

        this.shaderParams.clear();
        this.shaderParams.addAll(params);
        return this;
    }

    public TextureCombinerCommand init(Texture _tex, SmartShader _shader, ArrayList<TextureCombinerShaderParam> params, Texture _mask, int src, int dest) {
        return this.initSeparate(_tex, _shader, params, _mask, src, dest, 1, 771);
    }

    public TextureCombinerCommand init(Texture _tex, SmartShader _shader, ArrayList<TextureCombinerShaderParam> params) {
        this.tex = this.requireNonNull(_tex);
        this.blendSrc = 770;
        this.blendDest = 771;
        this.blendSrcA = 1;
        this.blendDestA = 771;
        this.shader = _shader;
        if (this.shaderParams == null) {
            this.shaderParams = new ArrayList();
        }

        this.shaderParams.clear();
        this.shaderParams.addAll(params);
        return this;
    }

    private Texture requireNonNull(Texture texture) {
        return texture == null ? Texture.getErrorTexture() : texture;
    }

    public static TextureCombinerCommand get() {
        TextureCombinerCommand textureCombinerCommand = pool.alloc();
        textureCombinerCommand.x = -1;
        textureCombinerCommand.tex = null;
        textureCombinerCommand.mask = null;
        textureCombinerCommand.shader = null;
        if (textureCombinerCommand.shaderParams != null) {
            textureCombinerCommand.shaderParams.clear();
        }

        return textureCombinerCommand;
    }
}
